package com.ktjy.config;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ktjy.entity.SysRight;
import com.ktjy.filter.WebFilter;
import com.ktjy.service.ISysRightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author lqm
 * @ClassName FilterConfig
 * @description: TODO
 */
//@Configuration
public class FilterConfig {
    @Autowired
    ISysRightService sysRightService;

//    @Bean
    public FilterRegistrationBean registFilter() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new WebFilter());
        QueryWrapper<SysRight> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().likeLeft(SysRight::getRightUrl, "/");
        List<SysRight> list = sysRightService.list(queryWrapper);
        for (SysRight temp:list) {
            registrationBean.addUrlPatterns(temp.getRightUrl());
        }
//        registrationBean.setOrder(5);
        return registrationBean;
    }
}
